Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to conditionally add components #100

Merged
merged 2 commits into from
Dec 11, 2024
Merged

Conversation

tusharmath
Copy link
Contributor

@tusharmath tusharmath commented Dec 11, 2024

  • chore: update ci
  • lint fixes
  • chore: update cargo
  • chore: update permissions
  • feat: add more APIs on ctx
  • refactor: rename Expr to Context
  • doc: update documentation
  • chore: update release config
  • chore: update condition for release build
  • chore: update changelog template
  • chore: use default .release-plz.toml
  • chore: rename workflow name
  • chore: fix workflow name
  • chore: release v0.5.0 (chore: release v0.5.0 #77)
  • chore: disable publish for macros
  • chore: revert version
  • chore: release v0.5.0 (chore: release v0.5.0 #78)
  • chore: revert version
  • chore: release v0.5.0 (chore: release v0.5.0 #79)
  • chore: update release config
  • chore: disable release for macros
  • chore: enable release always
  • chore: move macros to dev deps
  • chore: add workspaces back
  • chore: update release config
  • chore: update release config
  • chore: add version to macros
  • chore: move macros to deps
  • chore: reset release flags
  • chore: release v0.5.0 (chore: release v0.5.0 #82)
  • chore: update workflow for release
  • chore: add concurrency in release
  • chore: revert commit
  • chore: release macros also
  • chore: release v0.5.0 (chore: release v0.5.0 #84)
  • chore: update dependencies
  • chore: run release only when build is successfull
  • chore: run release on main only
  • chore: enable macros to be published
  • chore: add metadata fields to Cargo.toml for gh-workflow and gh-workflow-macros
  • chore(gh-workflow-macros): release v0.5.0 (chore(gh-workflow-macros): release v0.5.0 #86)
  • chore: release v0.5.1 (chore: release v0.5.1 #87)
  • doc: add module documentation for gh-workflow
  • feat: add gh-workflow-tailcall
  • doc: improve documentation for TailcallWorkflow
  • refactor: use gh-workflow-tailcall in the test
  • chore: release (chore: release #91)
  • doc: update readme
  • fix: drop v prefix from uses API
  • chore: release (chore: release #92)
  • fix: jobs dependency id generator (fix: jobs dependency id generator #94)
  • chore: release (chore: release #95)
  • chore: add readme
  • chore: release (chore: release #96)
  • feat: add benchmark to workflow (feat: add benchmark to workflow #97)
  • add when prefixed operators

Summary by CodeRabbit

  • New Features

    • Enhanced workflow configuration with new methods for conditional job, event, and environment variable additions.
    • Introduced methods for conditional step, environment variable, and dependency management within jobs.
  • Bug Fixes

    • Improved clarity and maintainability of workflow generation by consolidating job creation logic.
  • Refactor

    • Restructured existing methods for better organization and reduced complexity in workflow definitions.
    • Updated visibility of certain methods to streamline functionality.

Copy link

coderabbitai bot commented Dec 11, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve substantial modifications to the Workflow and Job structs in the workflow.rs files across two crates. The to_github_workflow method has been restructured to create GitHub workflows with explicit job definitions and conditions. New methods have been introduced to both structs, allowing for conditional additions of jobs, events, environment variables, and steps. Additionally, the visibility of the build_and_test method has been changed from public to private, and several helper functions have been removed to streamline the workflow generation process.

Changes

File Path Change Summary
crates/gh-workflow-tailcall/src/workflow.rs - Restructured to_github_workflow method for direct workflow creation with detailed job definitions.
- Changed visibility of build_and_test to private.
- Removed helper functions release_job and release_pr_job.
crates/gh-workflow/src/workflow.rs - Added methods for conditional job and event additions: add_job_when, add_event_when, add_env_when in Workflow.
- Added methods for conditional steps and dependencies in Job: add_step_when, add_env_when, add_needs_when.

Possibly related PRs

  • feat: add benchmark to workflow #97: The changes in this PR involve modifications to the build_and_test method in the Workflow struct, which is also a focus of the main PR. Both PRs deal with the restructuring of this method to enhance its functionality, particularly in relation to conditional job additions based on the benchmarks field.

🐰 In a world where workflows grow,
A rabbit hops to and fro.
With jobs that dance and steps that play,
Conditions guide them on their way.
So let us cheer for code so bright,
Creating magic, pure delight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 101b31d and 002db53.

📒 Files selected for processing (1)
  • crates/gh-workflow-tailcall/src/workflow.rs (2 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tusharmath tusharmath changed the title feat add when feat: add support to conditionally add components Dec 11, 2024
@tusharmath tusharmath merged commit 0362810 into main Dec 11, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Dec 11, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
crates/gh-workflow-tailcall/src/workflow.rs (5)

67-68: Simplify unnecessary borrowing and cloning

The expressions (&cond).clone() and (&build).clone() unnecessarily borrow the values before cloning. You can call .clone() directly on cond and build.

Apply this diff to simplify the code:

-    .cond((&cond).clone())
-    .add_needs((&build).clone())
+    .cond(cond.clone())
+    .add_needs(build.clone())
🧰 Tools
🪛 GitHub Check: Build and Test

[failure] 67-67:
this expression borrows a value the compiler would automatically borrow


[failure] 68-68:
this expression borrows a value the compiler would automatically borrow


74-74: Simplify unnecessary borrowing and cloning

The expression (&permissions).clone() needlessly borrows permissions before cloning. You can call .clone() directly on permissions.

Apply this diff:

-    .permissions((&permissions).clone())
+    .permissions(permissions.clone())
🧰 Tools
🪛 GitHub Check: Build and Test

[failure] 74-74:
this expression borrows a value the compiler would automatically borrow


79-79: Simplify unnecessary borrowing and cloning

The use of (&cond).clone() is redundant. You can simplify it by cloning cond directly.

Apply this diff:

-    .cond((&cond).clone())
+    .cond(cond.clone())
🧰 Tools
🪛 GitHub Check: Build and Test

[failure] 79-79:
this expression borrows a value the compiler would automatically borrow


84-84: Simplify unnecessary borrowing and cloning

Similarly, (&build).clone() can be simplified by cloning build directly without borrowing.

Apply this diff:

-    .add_needs((&build).clone())
+    .add_needs(build.clone())
🧰 Tools
🪛 GitHub Check: Build and Test

[failure] 84-84:
this expression borrows a value the compiler would automatically borrow


97-97: Simplify unnecessary borrowing and cloning

In this line, (&build).clone() can be simplified to build.clone().

Apply this diff:

-    .add_job("build", (&build).clone())
+    .add_job("build", build.clone())
🧰 Tools
🪛 GitHub Check: Build and Test

[failure] 97-97:
this expression borrows a value the compiler would automatically borrow

crates/gh-workflow/src/workflow.rs (1)

104-112: Consider refactoring to reduce code duplication in conditional methods

Multiple methods (add_job_when, add_event_when, add_env_when, add_step_when, add_env_when in Job, add_needs_when, add_with_when) share a similar pattern for conditionally adding elements based on a boolean condition. Consider refactoring these methods to reduce code duplication, possibly through a generic helper function or macro.

Also applies to: 145-153, 163-171, 267-275, 296-303, 312-319, 582-589

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between edc5edb and 101b31d.

📒 Files selected for processing (2)
  • crates/gh-workflow-tailcall/src/workflow.rs (2 hunks)
  • crates/gh-workflow/src/workflow.rs (6 hunks)
🧰 Additional context used
🪛 GitHub Check: Build and Test
crates/gh-workflow-tailcall/src/workflow.rs

[failure] 67-67:
this expression borrows a value the compiler would automatically borrow


[failure] 68-68:
this expression borrows a value the compiler would automatically borrow


[failure] 74-74:
this expression borrows a value the compiler would automatically borrow


[failure] 79-79:
this expression borrows a value the compiler would automatically borrow


[failure] 84-84:
this expression borrows a value the compiler would automatically borrow


[failure] 97-97:
this expression borrows a value the compiler would automatically borrow

🔇 Additional comments (12)
crates/gh-workflow-tailcall/src/workflow.rs (5)

44-44: Initialization of Rust flags is correct

Setting RustFlags::deny("warnings") ensures that all Rust compiler warnings are treated as errors, promoting code quality.


46-54: Event configuration is correctly set

The event variable is properly configured to trigger on pushes to "main" and pull request events (Opened, Synchronize, Reopened) targeting the "main" branch.


56-58: Conditional logic for workflow execution is appropriate

The conditions is_main and is_push are correctly combined to determine when the workflow should execute, ensuring it runs only on pushes to the "main" branch.


Line range hint 103-134: Conditional addition of benchmarking step is well-implemented

Using add_step_when to conditionally add the "Cargo Bench" step based on the benchmarks flag enhances the flexibility and readability of the workflow configuration.


140-140: Streamlined conversion to GitHub workflow

Utilizing value.to_github_workflow() in the From<Workflow> implementation simplifies the conversion process and improves code clarity.

crates/gh-workflow/src/workflow.rs (7)

104-112: Conditional job addition method is well-designed

The add_job_when method enhances the Workflow struct by allowing jobs to be added conditionally, increasing flexibility.


145-153: Conditional event addition improves configurability

The add_event_when method allows events to be added to the workflow based on a condition, enhancing configurability.


163-171: Conditional environment variable addition is appropriate

The add_env_when method enables conditional addition of environment variables to the workflow, maintaining consistency with other conditional methods.


267-275: Conditional step addition in Job struct is well-implemented

The add_step_when method allows steps to be added to a job conditionally, improving the expressiveness of job configurations.


296-303: Conditional environment variable addition in Job

The add_env_when method in the Job struct allows for conditional addition of environment variables, enhancing flexibility.


312-319: Conditional dependency addition in Job

The add_needs_when method enables conditional addition of job dependencies, promoting dynamic workflow definitions.


582-589: Conditional input addition in Step<Use>

The add_with_when method provides the ability to conditionally add input parameters to a step, enhancing the configurability of actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant